﻿@using Think9.Models;
@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<input style="display:none" id="sys_flag" value="ddv1">
<input style="display:none" id="Pu_from" value="@ViewBag.PuFrom">
<input style="display:none" id="Pu_tbid" value="@ViewBag.PuTbId">
<input style="display:none" id="Pu_indexid" value="@ViewBag.PuIndexId">
<input style="display:none" id="Pu_id" value="@ViewBag.PuId">
<input style="display:none" id="Pu_v" value="@ViewBag.PuV">

<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script src="~/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="~/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(["table", "form", "exLayer", "exUtils", "miniPage", "laydate"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let miniPage = layui.miniPage;
        let laydate = layui.laydate;

        let $ = layui.$;

        form.render(); //初始化表单，要加上，不然刷新部分组件可能会不加载

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysTable/RuleList/GetSysParameter",
            method: "get",
            page: false,
            height: '300px',
            defaultToolbar: [],
            toolbar: "#toolbarTpl",
            cols: [[
                { type: "radio", fixed: 'left' }
                , { field: "Value", hide: true }
                , { field: "Text", title: "系统参数" }
            ]],
            done: function (res, curr, count) {
                $('th').hide();//表头隐藏的样式
                console.log(res, curr, count);
            }
        });

        //查询
        form.on("submit(search)", function (data) {
            $("#searchfield").hide();
            var _list = [];
            getControlSearch(_list);
            console.log(_list);

            ThisTable.reload({
                where: { flag: $('#sys_flag').val(), "list": _list },
                page: { curr: 1 }
            });
            return false;
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "OK":
                    getSelect(obj);
                    break;
                case "searchShow":
                    searchShow();
                    break;
            }
        });

        function searchShow() {
            var display = $('#searchfield').css('display');
            if (display == 'none') {
                $("#searchfield").show();
            }
            else {
                $("#searchfield").hide();
            }
        }

        //从控件读值
        function getControlSearch(_list) {
            var _row = { ClassID: $('#sys_flag').val(), Text: $('#dictid').val(), Value: 'dictid' };
            _list.push(_row);
        }

        //确定选择
        function getSelect(obj) {
            var strv = "";
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            if (checkStatus.data.length > 0) {
                strv = checkStatus.data[0].Value;
            }
            $(window.parent.document).find('#valuekey').val(strv);
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

    })</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    <button class="layui-btn layui-btn-normal" lay-event="OK" id="OK">确定选择</button>
</script>